package com.asnike.selector{
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	
	public class CampItem extends Sprite{
		
		public var over:Sprite;
		public var price:TextField;
		public var checkBox:Sprite;
		public var itemName:TextField;
		
		public function CampItem(){
			initOver();
			initText();
			initEvent();
		}
		private function initOver():void{
			over.visible = false;
		}
		private function initText():void{
			var format:TextFormat;
			
			format = new TextFormat( 'ygo340', 12 );
			itemName.defaultTextFormat = format;
			itemName.embedFonts = true;
			itemName.selectable = false;
			itemName.mouseEnabled = false;
			itemName.multiline = false;
			itemName.wordWrap = false;
			itemName.autoSize = TextFieldAutoSize.LEFT;
			
			format = new TextFormat( 'ygo340', 12 );
			price.defaultTextFormat = format;
			price.embedFonts = true;
			price.selectable = false;
			price.mouseEnabled = false;
			price.multiline = false;
			price.autoSize = TextFieldAutoSize.LEFT;
		}
		private function initEvent():void{
			buttonMode = true;
			addEventListener( MouseEvent.MOUSE_OVER, mouseOver );
			addEventListener( MouseEvent.MOUSE_OUT, mouseOut );
		}
		private function mouseOver( $e:MouseEvent ):void{
			over.visible = true;
		}
		private function mouseOut( $e:MouseEvent ):void{
			over.visible = false;
		}
		
		internal function setItemName( $name:String ):void{
			itemName.text = $name;
		}
		
		internal function setPrice( $value:int ):void{
			price.text = $value.toString() + '원';
		}
		
		internal function setImage( $url:String ):void{
			var loader:Loader, bitmap:Bitmap;
			
			loader = new Loader;
			loader.contentLoaderInfo.addEventListener( Event.COMPLETE, function( $e:Event ):void{
				$e.target.removeEventListener( $e.type, arguments.callee );
				bitmap = new Bitmap( $e.target.content.bitmapData.clone() );
				bitmap.name = 'image';
				addChildAt( bitmap, 0 );
			} );
			loader.load( new URLRequest( $url ) );
		}
		
		internal function getName():String{
			return itemName.text;
		}
		internal function getPrice():int{
			return int( price.text.replace( '원', '' ) );
		}
		
	}
}